<?php
// 更新数据
// 接收前端传递过来的id,name,price,num从数据库里去更新数据

$id = $_GET['id'];
$name = $_GET['name'];
$price = $_GET['price'];
$num = $_GET['num'];

$conn = mysqli_connect('localhost', 'root', 'root', '2008');
mysqli_query($conn, "set charset 'utf8'");
mysqli_query($conn, "set character set 'utf8'");

$sql = "update shop set name='$name',price=$price,num=$num where id=$id";

$res = mysqli_query($conn, $sql);

if ($res) {
  echo json_encode(array(
    "code" => 200,
    "body" => array(
      "msg" => "更新成功"
    )
  ));
} else {
  echo json_encode(array(
    "code" => 201,
    "body" => array(
      "msg" => "网络错误，请重试"
    )
  ));
}
?>